const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
    entry: path.resolve(__dirname, '../src/index.js'),
    output: {
        path: path.resolve(__dirname, '../build'),
        filename: './js/bundle.js',
        publicPath:"/"
    },
    module:
    {
        rules: [{
            test: /\.html$/i,
            use: ["html-loader"]
        },
        {
            test: /\.ejs$/i,
            loader: "ejs-loader",
            options: {
                variable: 'data', // 可以在模块当中使用data进行数据处理
               
            }
        }]
    },
    resolve: {
        alias: {
            $v: path.resolve(__dirname, "../src/views"),
            $r: path.resolve(__dirname, "../src/route"),
            $a: path.resolve(__dirname, "../src/api"),
        },
        // 尝试按顺序解析这些后缀名。如果有多个文件有相同的名字，但后缀名不同，webpack 会解析列在数组首位的后缀的文件 并跳过其余的后缀。
        extensions: [".js", ".json", ".ejs"],
    },

    mode: 'production',
    plugins: [
        new HtmlWebpackPlugin(
            {
                filename: "index.html",
                template: path.resolve(__dirname, '../public/index.html')
            }),
        new CopyWebpackPlugin({
            patterns: [{
                from: path.resolve(__dirname, '../public'),
                to: "public",
                globOptions: {
                    ignore: ["**/index.html"]
                }
            }],
        })
    ],
}